package com.gomore.opple.module.incomeandexpense.detailactivity;

import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gomore.opple.OppleApplication;
import com.gomore.opple.R;
import com.gomore.opple.common.GlobalConstant;
import com.gomore.opple.module.BaseActivity;
import com.gomore.opple.module.IntentStart;
import com.gomore.opple.utils.BigDecimalUtils;
import com.gomore.opple.utils.DateUtil;
import com.gomore.opple.utils.DensityUtil;
import com.gomore.opple.web.cgform.applybill.entity.TOApplyBillEntity;

import butterknife.Bind;

/**
 * Created by asus on 2017/5/26.
 */
public class ApplyDetailActivity extends BaseActivity {
    @Bind(R.id.progress)
    ImageView progress;
    @Bind(R.id.start_date)
    TextView start_date;
    @Bind(R.id.finish_type)
    TextView finish_type;
    @Bind(R.id.end_date)
    TextView end_date;
    @Bind(R.id.account)
    TextView account;
    @Bind(R.id.time)
    TextView time;
    @Bind(R.id.bill_number)
    TextView bill_number;
    private TOApplyBillEntity toApplyBillEntity;

    @Override
    protected void initalizeViewData() {
        super.initalizeViewData();
        if (getIntent() != null && getIntent().getSerializableExtra(IntentStart.TOAPPLYBILLENTITY) != null) {
            toApplyBillEntity = (TOApplyBillEntity) getIntent().getSerializableExtra(IntentStart.TOAPPLYBILLENTITY);
        }
    }

    @Override
    protected void initalizeViews() {
        if (toApplyBillEntity == null) {
            return;
        }
        int screenWidth = DensityUtil.screenWith(OppleApplication.getInstance());
        int margin = screenWidth / 6;
        int progressWidth = screenWidth - 2 * margin + DensityUtil.dpToPx(this, 20);
        int progressHeight = progressWidth * 68 / 541;
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) progress.getLayoutParams();
        params.width = progressWidth;
        params.height = progressHeight;
        progress.setLayoutParams(params);
        if (toApplyBillEntity.getBillStates() != null) {
            if (toApplyBillEntity.getBillStates().equals(GlobalConstant.ApplyState.SUBMIT) ||
                    toApplyBillEntity.getBillStates().equals(GlobalConstant.ApplyState.PAYING)) {
                progress.setImageResource(R.mipmap.start_apply);
                finish_type.setText(GlobalConstant.ApplyState.getStateNameByCode(GlobalConstant.ApplyState.ACCOMPLISHED));
                finish_type.setTextColor(getResources().getColor(R.color.line_color));
            } else {
                progress.setImageResource(R.mipmap.finish_apply);
                finish_type.setText(GlobalConstant.ApplyState.getStateNameByCode(toApplyBillEntity.getBillStates()));
                finish_type.setTextColor(getResources().getColor(GlobalConstant.ApplyState.getColorByCode(toApplyBillEntity.getBillStates())));
                if (toApplyBillEntity.getUpdateDate() != null) {
                    end_date.setText(DateUtil.fomatforDate(toApplyBillEntity.getUpdateDate(), DateUtil.DATE_FORMATTER_1));
                }
            }
        }
        if (toApplyBillEntity.getCreateDate() != null) {
            start_date.setText(DateUtil.fomatforDate(toApplyBillEntity.getCreateDate(), DateUtil.DATE_FORMATTER_1));
        }
        if (toApplyBillEntity.getApplyMoney() != null) {
            account.setText(BigDecimalUtils.forMate(toApplyBillEntity.getApplyMoney()).toString());
        }
        if (toApplyBillEntity.getCreateDate() != null) {
            time.setText(DateUtil.fomatforDate(toApplyBillEntity.getCreateDate(), DateUtil.DATE_FORMATTER_1));
        }
        if (toApplyBillEntity.getBillNumber() != null) {
            bill_number.setText(toApplyBillEntity.getBillNumber());
        }
    }

    @Override
    protected void initializeDependencyInjector() {

    }

    @Override
    protected int getLayoutView() {
        return R.layout.activity_apply_detail;
    }
}
